package org.example.MedicalCrowdsourcing.service;

import java.lang.Exception;
import java.lang.String;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingCompleteProjectInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingCreateProjectInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingDeleteProjectInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetAllProjectIdsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectBasic1InputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectBasic2InputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectHistoryDetailsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectHistoryIdsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectTimesInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetProjectTransactionsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingGetTransactionDetailsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingProjectHistoriesInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingProjectIdsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingProjectTransactionsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingProjectsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingTransactionsInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingUpdateProjectInputBO;
import org.example.MedicalCrowdsourcing.model.bo.MedicalCrowdsourcingVerifyProjectHashInputBO;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.transaction.manager.AssembleTransactionProcessor;
import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory;
import org.fisco.bcos.sdk.transaction.model.dto.CallResponse;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@NoArgsConstructor
@Data
public class MedicalCrowdsourcingService {
  public static final String ABI = org.example.MedicalCrowdsourcing.utils.IOUtil.readResourceAsString("abi/MedicalCrowdsourcing.abi");

  public static final String BINARY = org.example.MedicalCrowdsourcing.utils.IOUtil.readResourceAsString("bin/ecc/MedicalCrowdsourcing.bin");

  public static final String SM_BINARY = org.example.MedicalCrowdsourcing.utils.IOUtil.readResourceAsString("bin/sm/MedicalCrowdsourcing.bin");

  @Value("${system.contract.medicalCrowdsourcingAddress}")
  private String address;

  @Autowired
  private Client client;

  AssembleTransactionProcessor txProcessor;

  @PostConstruct
  public void init() throws Exception {
    this.txProcessor = TransactionProcessorFactory.createAssembleTransactionProcessor(this.client, this.client.getCryptoSuite().getCryptoKeyPair());
  }

  public CallResponse owner() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "owner", Arrays.asList());
  }

  public TransactionResponse deleteProject(MedicalCrowdsourcingDeleteProjectInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "deleteProject", input.toArgs());
  }

  public CallResponse projectTransactions(MedicalCrowdsourcingProjectTransactionsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "projectTransactions", input.toArgs());
  }

  public TransactionResponse createProject(MedicalCrowdsourcingCreateProjectInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "createProject", input.toArgs());
  }

  public CallResponse getProjectBasic1(MedicalCrowdsourcingGetProjectBasic1InputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectBasic1", input.toArgs());
  }

  public CallResponse projects(MedicalCrowdsourcingProjectsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "projects", input.toArgs());
  }

  public CallResponse getProjectBasic2(MedicalCrowdsourcingGetProjectBasic2InputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectBasic2", input.toArgs());
  }

  public CallResponse getTransactionDetails(MedicalCrowdsourcingGetTransactionDetailsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getTransactionDetails", input.toArgs());
  }

  public TransactionResponse updateProject(MedicalCrowdsourcingUpdateProjectInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateProject", input.toArgs());
  }

  public CallResponse verifyProjectHash(MedicalCrowdsourcingVerifyProjectHashInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "verifyProjectHash", input.toArgs());
  }

  public CallResponse getProjectTimes(MedicalCrowdsourcingGetProjectTimesInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectTimes", input.toArgs());
  }

  public CallResponse getProjectHistoryIds(MedicalCrowdsourcingGetProjectHistoryIdsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectHistoryIds", input.toArgs());
  }

  public CallResponse getAllProjectIds(MedicalCrowdsourcingGetAllProjectIdsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getAllProjectIds", input.toArgs());
  }

  public CallResponse transactions(MedicalCrowdsourcingTransactionsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "transactions", input.toArgs());
  }

  public CallResponse projectHistories(MedicalCrowdsourcingProjectHistoriesInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "projectHistories", input.toArgs());
  }

  public CallResponse projectIds(MedicalCrowdsourcingProjectIdsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "projectIds", input.toArgs());
  }

  public CallResponse historyCount() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "historyCount", Arrays.asList());
  }

  public TransactionResponse completeProject(MedicalCrowdsourcingCompleteProjectInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "completeProject", input.toArgs());
  }

  public CallResponse getProjectHistoryDetails(MedicalCrowdsourcingGetProjectHistoryDetailsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectHistoryDetails", input.toArgs());
  }

  public CallResponse getProjectTransactions(MedicalCrowdsourcingGetProjectTransactionsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getProjectTransactions", input.toArgs());
  }

  public CallResponse projectCount() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "projectCount", Arrays.asList());
  }
}
